package com.tian.authen.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.tian.authen.controller.TestRequest;
import com.tian.authen.dao.OauthAuthorizeDao;
import com.tian.authen.dao.OauthClientDao;
import com.tian.authen.entity.OauthAuthorize;
import com.tian.authen.entity.OauthClient;
import com.tian.authen.entity.User;
import com.tian.authen.service.IOauthAuthorizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.tian.authen.entity.table.OauthClientTableDef.OAUTH_CLIENT;
import static com.tian.authen.entity.table.OauthAuthorizeTableDef.OAUTH_AUTHORIZE;

/**
 * @author zhumengping
 * @title: OauthAuthorizeServiceImpl
 * @projectName zhump-cloud
 * @date 2023/8/8 16:28
 */
@Service
public class OauthAuthorizeServiceImpl extends ServiceImpl<OauthAuthorizeDao, OauthAuthorize> implements IOauthAuthorizeService {

    @Autowired
    private OauthClientDao oauthClientDao;

    @Override
    public List<OauthClient> test(TestRequest dto) {


        QueryWrapper on = QueryWrapper.create()
                .select(OAUTH_CLIENT.ALL_COLUMNS)
                .select(OAUTH_AUTHORIZE.ID, OAUTH_AUTHORIZE.OAUTH_USER_NAME)
                .from(OAUTH_CLIENT)
                .leftJoin(OAUTH_AUTHORIZE).on(OAUTH_CLIENT.CLIENT_ID.eq(OAUTH_AUTHORIZE.CLIENT_ID))
                .where(OAUTH_CLIENT.CLIENT_ID.eq(dto.getClientId()));

        return oauthClientDao.selectListByQueryAs(on, OauthClient.class);
    }
}
